Skip to content

London | 26-Java-June | Fatma Arslantas | Sprint 1 | Reverse Numbers#21

Open
AFatmaa wants to merge 1 commit into
CodeYourFuture:mainfrom
AFatmaa:sprint-1-reverse-numbers
Open

London | 26-Java-June | Fatma Arslantas | Sprint 1 | Reverse Numbers#21
AFatmaa wants to merge 1 commit into
CodeYourFuture:mainfrom
AFatmaa:sprint-1-reverse-numbers

Conversation

@AFatmaa

@AFatmaa AFatmaa commented Jun 29, 2026

Copy link
Copy Markdown

Learners, PR Template

Self checklist

  • I have titled my PR with Region | Cohort | FirstName LastName | Sprint | Assignment Title
  • My changes meet the requirements of the task
  • I have tested my changes
  • My changes follow the style guide

Changelist

This PR adds the Sprint 1 Reverse Numbers exercise.

Changes:

  • Added a ReverseNumbers class
  • Added a private method to reverse the digits of a number
  • Called the method from the main method
  • Used clear method and variable names
  • Added JavaDoc documentation
  • Tested the program in IntelliJ using the example number 3956

Example:
3956 returns 6593

Questions

I don’t have any questions, thank you.

@AFatmaa AFatmaa added 📅 Sprint 1 Assigned during Sprint 1 of this module Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. labels Jun 29, 2026
@jabeywick jabeywick self-assigned this Jul 3, 2026
Comment thread src/ReverseNumbers.java
System.out.println("Reversed number: " + reversedNumber);
}

/**

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice javadoc!

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Comment thread src/ReverseNumbers.java
int remaningNumber = number;

while (remaningNumber > 0) {
int digit = remaningNumber % 10;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks great 😄

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Comment thread src/ReverseNumbers.java
int reversedNumber = 0;
int remaningNumber = number;

while (remaningNumber > 0) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What changes would you have to make to get this working for negative numbers?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To support negative numbers, I would handle the sign separately.

The current loop only works for positive numbers because it runs while remainingNumber > 0. For a negative number, I would first check whether the original number is negative, then reverse the absolute value of the number, and finally return the result as negative again if needed.

I could update the method like this:

private static int reverseNumber(int number) {
    boolean isNegative = number < 0;
    int remainingNumber = Math.abs(number);
    int reversedNumber = 0;

    while (remainingNumber > 0) {
        int digit = remainingNumber % 10;
        reversedNumber = reversedNumber * 10 + digit;
        remainingNumber = remainingNumber / 10;
    }

    if (isNegative) {
        return -reversedNumber;
    }

    return reversedNumber;
}

For example, -3956 would return -6593.

Would this be a good way to handle negative numbers?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep nice one - this looks good to me!!

@jabeywick jabeywick added Complete Volunteer to add when work is complete and all review comments have been addressed. and removed Review in progress labels Jul 3, 2026
@jabeywick

Copy link
Copy Markdown

This looks really good, Fatma 😄 I like how you've structured the class and the logic looks good. Left a question around working with negative numbers .

@AFatmaa

AFatmaa commented Jul 4, 2026

Copy link
Copy Markdown
Author

Thank you @jabeywick! 🥳 I’ve just answered your question ☺️

@jabeywick jabeywick removed the Needs Review Trainee to add when requesting review. PRs without this label will not be reviewed. label Jul 10, 2026
@jabeywick jabeywick removed their assignment Jul 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Complete Volunteer to add when work is complete and all review comments have been addressed. 📅 Sprint 1 Assigned during Sprint 1 of this module

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants